import 'package:flutter/material.dart';
import 'package:flutter_test_demo/pages/home/components/DiscoverPage.dart';
import 'package:flutter_test_demo/pages/home/components/MessagePage.dart';
import 'package:flutter_test_demo/pages/home/components/MyPage.dart';
import 'package:flutter_test_demo/pages/home/components/RecommendPage.dart';

class Home extends StatefulWidget {
  final int pageIndex;
  Home({Key key , this.pageIndex = 0}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int currentIndex = 0;
  // tab页
  List _pageList = [RecommendPage(), DiscoverPage(), MessagePage(), MyPage()];

  @override
  void initState() { 
    super.initState();
    currentIndex = widget.pageIndex;
  }


  List<BottomNavigationBarItem> _BottomItem = [
    BottomNavigationBarItem(
        title: Text('首页'),
        icon: Icon(Icons.home),
        backgroundColor: Color(0xFF009688)),
    BottomNavigationBarItem(
        title: Text('发现'),
        icon: Icon(Icons.search),
        backgroundColor: Color(0xFF009688)),
    BottomNavigationBarItem(
        title: Text('订阅'),
        icon: Icon(Icons.message),
        backgroundColor: Color(0xFF009688)),
    BottomNavigationBarItem(
        title: Text('我的'),
        icon: Icon(Icons.person),
        backgroundColor: Color(0xFF009688)),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: this._pageList[this.currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index) {
          print(index);
          setState(() {
            this.currentIndex = index;
          });
        },
        currentIndex: currentIndex,
        items: this._BottomItem,
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
